package ltd.trackan.messagecenter.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import ltd.trackan.messagecenter.common.ValueCommon;
import ltd.trackan.messagecenter.model.coommon.RestBean;
import ltd.trackan.messagecenter.model.entity.Jdcertificate;
import ltd.trackan.messagecenter.service.JDCertificateService;
import ltd.trackan.messagecenter.mapper.JdcertificateMapper;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * @author wxa
 */
@Service
@Slf4j
public class JDCertificateServiceImpl extends ServiceImpl<JdcertificateMapper, Jdcertificate>
        implements JDCertificateService {
    
    @Override
    public RestBean<String> updateJDCertificateState(Set<String> accounts, int state) {
        try {
            if (state != 0 && state != 1) {
                return RestBean.failure("请输入正确的状态");
            }
            accounts.forEach(account -> {
                String id = ValueCommon.JD_ACCOUNT_MAPPER_ID.get(account);
                if (id != null) {
                    Jdcertificate jdcertificate = new Jdcertificate();
                    jdcertificate.setUId(id);
                    jdcertificate.setState(state);
                    if (!this.updateById(jdcertificate)) {
                        log.error("当前账号的id{}无法更新{}状态", id, state);
                    }
                } else {
                    log.error("当前账号{}无法找到对应的id", account);
                }
            });
            return RestBean.success();
        } catch (Exception e) {
            return RestBean.failure(e.getMessage());
        }
    }
}




